package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.sys.shiro.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.InfoManagerEntity;
import io.renren.modules.sys.service.InfoManagerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 车辆信息表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-11-15 08:57:33
 */
@RestController
@RequestMapping("/sys/infomanager")
public class InfoManagerController {
    @Autowired
    private InfoManagerService infoManagerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:infomanager:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = infoManagerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{carId}")
    @RequiresPermissions("sys:infomanager:info")
    public R info(@PathVariable("carId") Integer carId){
			InfoManagerEntity infoManager = infoManagerService.selectById(carId);

        return R.ok().put("infoManager", infoManager);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:infomanager:save")
    public R save(@RequestBody InfoManagerEntity infoManager){
        infoManager.setDeptId(ShiroUtils.getUserEntity().getDeptId());
			infoManagerService.insert(infoManager);


        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:infomanager:update")
    public R update(@RequestBody InfoManagerEntity infoManager){
			infoManagerService.updateById(infoManager);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:infomanager:delete")
    public R delete(@RequestBody Integer[] carIds){
			infoManagerService.deleteBatchIds(Arrays.asList(carIds));

        return R.ok();
    }

}
